package ykc.demo;

import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        String username=(String) session.getAttribute("username");
        if('r'!=username.charAt(username.length() - 1)){
            request.setAttribute("msg","用户名错误，无法访问，请重新输入");
            request.getRequestDispatcher("/input").forward(request,response);
            return false;
        }
        return true;
    }
}
